package com.kuang.controller;

import com.kuang.pojo.AstLocalCloseWell;
import com.kuang.pojo.AstLocalOpenWell;
import com.kuang.service.asset.AstLocalCloseWellService;
import com.kuang.service.asset.AstLocalOpenWellService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
public class AstLocalCloseWellController {

    @Resource
    AstLocalCloseWellService astLocalCloseWellService;

    /**
     * 设备端本地关井 全部数据
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstLocalCloseWells")
    public String getAstLocalCloseWells(Model model) {
        List<AstLocalCloseWell> astLocalCloseWells = astLocalCloseWellService.selectAll();
        model.addAttribute("datas", astLocalCloseWells);
        model.addAttribute("device_code", "");
        model.addAttribute("ver", "");
        return "mqtt/ast_local_close_well_list";
    }

    /**
     * 设备端本地关井 通过条件
     *
     * @param model
     * @return
     */
    @PostMapping("getAstLocalCloseWellsByExample")
    public String getAstLocalCloseWellsByExample(AstLocalCloseWell astLocalCloseWell, Model model) {
        List<AstLocalCloseWell> astLocalCloseWells = astLocalCloseWellService.selectAllByExample(astLocalCloseWell);
        model.addAttribute("datas", astLocalCloseWells);
        model.addAttribute("device_code", astLocalCloseWell.getDevice_code());
        model.addAttribute("ver", astLocalCloseWell.getVer());
        return "mqtt/ast_local_close_well_list";
    }

    /**
     * 获取设备信息通过id
     *
     * @param model
     * @return
     */
    @RequestMapping("getAstLocalCloseWellById/{id}")
    public String getAstLocalCloseWellById(@PathVariable("id") String id, Model model) {
        AstLocalCloseWell astLocalCloseWell = new AstLocalCloseWell();
        astLocalCloseWell.setAst_local_close_well_id(id);
        List<AstLocalCloseWell> astLocalCloseWells = astLocalCloseWellService.selectAllByExample(astLocalCloseWell);
        model.addAttribute("data", astLocalCloseWells.get(0));
        return "mqtt/ast_local_close_well_from";
    }

}
